﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MadLibrary.Collections;
namespace MadLibrary.Web
{
    /// <summary>
    /// Serves as base for main web documents and thier main properties.
    /// </summary>
    public class WebFile
    {
        /// <summary>
        /// Gets or sets name of current web file.
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// Creates new empty web file.
        /// </summary>
        public WebFile()
        {
            this.Name = string.Empty;
        }
        /// <summary>
        /// Creates new web file with specified name.
        /// </summary>
        /// <param name="Name">Specifies name of new web file.</param>
        public WebFile(string Name)
        {
            this.Name = Name;
        }
        /// <summary>
        /// Serves as base for document content loading.
        /// </summary>
        /// <param name="Path">Specifies path from which should be content loaded.</param>
        public virtual void LoadContent(string Path)
        { 
            
        }
    }
    /// <summary>
    /// Holds and manages collection of web files.
    /// </summary>
    public class WebFiles : Collection<WebFile>
    {
        /// <summary>
        /// Creates new empty WebFile collection.
        /// </summary>
        public WebFiles()
            : base()
        { 
            
        }
        /// <summary>
        /// Creates new WebFile collection with specified default web files.
        /// </summary>
        /// <param name="WebFiles">Specifies web files which have to be defaultly added to new WebFile collection.</param>
        public WebFiles(params WebFile[] WebFiles)
            : base(WebFiles)
        { 
            
        }
        /// <summary>
        /// Gets or sets web file by specified name.
        /// </summary>
        /// <param name="Name">Specifies name of file which has to be got or set.</param>
        /// <returns>WebFile with specified name.</returns>
        public WebFile this[string Name]
        {
            get 
            {
                foreach(WebFile w in this.data)
                {
                    if (w.Name == Name)
                        return w;
                }
                return null;
            }
            set
            { 
                int i = 0;
                List<int> col = new List<int>();
                foreach(WebFile w in this.data)
                {
                    if (w.Name == Name)
                        col.Add(i);
                    i++;
                }
                foreach(int h in col)
                {
                    this.data[h] = value;
                }
            }
        }
    }
}
